<?php
	if (isset($_GET['mode']) && $_GET['mode']=='direct') {
			echo "Sorry, no.";
			exit;
	}
	if (isset($_GET['c']) && preg_match('/^[[:alnum:]]+(\s+.+)?/', $_GET['c'])) {
		$fcmd = explode(" ", $_GET['c']);
		$ucmd = array_shift($fcmd);
		$cmds = file_get_contents('quix.txt');
		$reg = '/^(?P<cmd>'.$ucmd.')\s+(?P<full>(?P<protocol>[[:alnum:]\+\-\.]+):(?P<action>[^\s]+))(\s+(?P<name>.*))?$/m';
		if (preg_match_all($reg,$cmds,$matches,PREG_SET_ORDER)) {
			$cmd = end($matches);
			
			$tokens = array('%s_','%s','%r','%d','%t');
			$real = array(implode("_",$fcmd),@$_GET['u'],@$_GET['u'],@$_GET['t']);
			$cmd['action'] = str_replace($tokens,$real,$cmd['action']);
			$cmd['full'] = str_replace($tokens,$real,$cmd['full']);
			
			if ($cmd['protocol']=='javascript') {
				echo $cmd['action'];
			} elseif ($cmd['protocol']=='script') {
				echo "heads=document.getElementsByTagName('head'); if (heads.length==0){ alert('Sorry, couldn\'t execute script properly.'); }else{ q=document.getElementById('puixscript'); if(q){ q.parentNode.removeChild(q); } sc=document.createElement('script'); sc.src=\"".$cmd['action']."\"; sc.id='puixscript'; sc.type='text/javascript'; void(heads[0].appendChild(sc)); }";
			} else {
				echo 'function puix_exec(){setTimeout(function(){location.href="'.$cmd['full'].'";},0)}puix_exec();';
			}
		} else {
			echo "alert('No such command.');";
		}
	} else { ?>
		<a href="javascript:puix();function%20puix(){<?php echo str_replace(' ','%20',"var e=encodeURIComponent;var t=window.getSelection?window.getSelection():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:''));var c=window.prompt('Your command prompt to the web:');if(t!=''){if(c){c+=' '+t}else{c=''+t}}if(c){var u='").'http'.(@$_SERVER['HTTPS']=='on'?'s':'').'://'.$_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT']!='80'?':'.$_SERVER['SERVER_PORT']:'').substr($_SERVER['REQUEST_URI'],0,-(strlen($_SERVER['QUERY_STRING'])+1)).str_replace(' ','%20',"?c='+e(c)+'&t='+(document.title?e(document.title):'')+'&u='+(document.location?e(document.location):'');var d=''+document.location;if(d.substr(0,4)!='http'){window.location=u+'&mode=direct'}else{heads=document.getElementsByTagName('head');if(c.substring(0,1)==' '){var w=window.open(u+'&mode=direct');w.focus()}else if(heads.length==0){window.location=u+'&mode=direct'}else{q=document.getElementById('quix');if(q){q.parentNode.removeChild(q)}sc=document.createElement('script');sc.src=u;sc.id='puix';sc.type='text/javascript';void(heads[0].appendChild(sc))}}}"); ?>}">Puix</a>
<?php	}?>